
/**
/**
 * 顺序递增分组 AscendingGroups
 */
export const SIXTEEN_ASCENDING_GROUPS = [
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
  [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33],
  [34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
]

/**
 * 质数分组 PrimeGroups
 */
export const SIXTEEN_PRIME_GROUPS = [
  [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47], // 16个号码（质数+1）
  [4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26], // 16个号码（非质数）
  [27, 28, 30, 32, 33, 34, 35, 36, 38, 39, 40, 42, 44, 45, 46, 48, 49] // 17个号码（剩余非质数）
]

/**
 * 斐波那契数分组 FibonacciGroups
 */
export const SIXTEEN_FIBONACCI_GROUPS = [
  [1, 2, 3, 5, 8, 13, 21, 34, 4, 6, 7, 9, 10, 11, 12, 14], // 16个号码（斐波那契+非斐波那契混合）
  [15, 16, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32], // 16个号码（非斐波那契）
  [33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 17] // 17个号码（剩余非斐波那契+1）
]

/**
 * 中心扩展分组 CenterExpansionGroups
 */
export const SIXTEEN_CENTER_EXPANSION_GROUPS = [
  [14, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
  [2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 34, 35, 36, 37, 38, 39],
  [1, 3, 4, 15, 16, 32, 33, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
]

/**
 * 大中小号分组 LargeMidSmallGroups
 */
export const SIXTEEN_LARGE_MID_SMALL_GROUPS = [
  [1, 2, 3, 4, 5, 6, 7, 17, 18, 19, 20, 21, 22, 34, 35, 36], // 16个号码（小号到中号）
  [8, 9, 10, 11, 12, 13, 14, 23, 24, 25, 26, 27, 28, 37, 38, 39], // 16个号码（中号到大号）
  [15, 16, 29, 30, 31, 32, 33, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49] // 17个号码（大号+剩余）
]

/**
 * 金字塔分组 PyramidGroups
 */
export const SIXTEEN_PYRAMID_GROUPS = [
  [1, 2, 3, 4, 20, 21, 22, 23, 24, 25, 26, 27, 28, 47, 48, 49], // 16个号码（从边缘向中间）
  [5, 6, 7, 8, 14, 15, 16, 17, 18, 19, 29, 30, 31, 44, 45, 46], // 16个号码（从边缘向中间）
  [9, 10, 11, 12, 13, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43] // 17个号码（剩余）
]

/**
 * 四象限分组 QuadrantGroups
 */
export const SIXTEEN_QUADRANT_GROUPS = [
  [1, 2, 3, 4, 5, 6, 7, 13, 14, 15, 25, 26, 27, 37, 38, 39], // 16个号码（象限1-2）
  [8, 9, 10, 11, 12, 16, 17, 18, 19, 28, 29, 30, 31, 32, 40, 41], // 16个号码（象限3-4）
  [20, 21, 22, 23, 24, 33, 34, 35, 36, 42, 43, 44, 45, 46, 47, 48, 49] // 17个号码（剩余）
]

/**
 * 跳号分组（跳2）JumpTwoGroups
 * 奇偶分组 OddEvenGroups 一样
 */
export const SIXTEEN_JUMP_TWO_GROUPS = [
  [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31], // 16个号码（跳号分组1）
  [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32], // 16个号码（跳号分组2）
  [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49] // 17个号码（剩余）
]

/**
 * 模4分组 ModuloFourGroups
 */
export const SIXTEEN_MODULO_FOUR_GROUPS = [
  [1, 2, 5, 6, 9, 10, 13, 14, 17, 21, 25, 29, 33, 37, 41, 45], // 16个号码（模4=1,2）
  [3, 7, 11, 15, 18, 19, 22, 23, 26, 27, 30, 31, 34, 38, 42, 46], // 16个号码（模4=3,4）
  [4, 8, 12, 16, 20, 24, 28, 32, 35, 36, 39, 40, 43, 44, 47, 48, 49] // 17个号码（剩余模4组）
]

/**
 * 镜像分组 MirrorGroups
 */
export const SIXTEEN_MIRROR_GROUPS = [
  [1, 2, 3, 4, 5, 6, 7, 8, 42, 43, 44, 45, 46, 47, 48, 49], // 16个号码（对称镜像）
  [9, 10, 11, 12, 13, 14, 15, 16, 34, 35, 36, 37, 38, 39, 40, 41], // 16个号码（对称镜像）
  [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33] // 17个号码（中心对称）
]

/**
 * 交错分组 CrossingGroups
 */
export const SIXTEEN_CROSSING_GROUPS = [
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 43, 44, 45, 46, 47, 48], // 16个号码（奇偶交替）
  [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 37, 38, 39, 40, 41, 42], // 16个号码（奇偶交替）
  [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 49] // 17个号码（剩余号码）
]

/**
 * 和差分组 SumDifferenceGroups
 */
export const SIXTEEN_SUM_DIFFERENCE_GROUPS = [
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, 17, 22], // 16个号码（和差规律1）
  [14, 15, 18, 19, 20, 21, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33], // 16个号码（和差规律2）
  [28, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49] // 17个号码（剩余号码）
]

/**
 * 对角线分组 DiagonalGroups
 */
export const SIXTEEN_DIAGONAL_GROUPS = [
  [1, 2, 3, 4, 6, 7, 8, 11, 12, 13, 16, 17, 18, 21, 22, 23], // 16个号码（对角线1）
  [5, 9, 10, 14, 15, 19, 20, 24, 25, 26, 27, 28, 29, 30, 31, 32], // 16个号码（对角线2）
  [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49] // 17个号码（剩余号码）
]

/**
 * 和尾数分组 lastDigitGroups
 */
export const SIXTEEN_LAST_DIGIT_GROUPS = [
  [1, 2, 3, 4, 11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43], // 16个号码（尾数1-4）
  [5, 6, 7, 8, 15, 16, 17, 25, 26, 27, 35, 36, 37, 45, 46, 47], // 16个号码（尾数5-8）
  [9, 10, 14, 18, 19, 20, 24, 28, 29, 30, 34, 38, 39, 40, 44, 48, 49] // 17个号码（尾数9-0）
]

/**
 * 模3分组 moduloThreeGroups
 */
export const SIXTEEN_MODULO_THREE_GROUPS = [
  [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46], // 16个号码（模3=1）
  [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47], // 16个号码（模3=2）
  [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 49] // 17个号码（模3=0）
]

/**
 * 倍数分组 multipleGroups
 */
export const SIXTEEN_MULTIPLE_GROUPS = [
  [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48], // 第一组16个（3的倍数）
  [5, 10, 38, 20, 25, 47, 35, 40, 4, 8, 16, 28, 32, 44, 46, 49], // 第二组16个（5的倍数和其他）
  [1, 2, 7, 11, 13, 14, 17, 19, 22, 23, 26, 29, 31, 34, 37, 41, 43] // 第三组17个（剩余）
]

// Fisher-Yates 洗牌算法实现随机打乱
const shuffleArray = (array) => {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1))
    ;[array[i], array[j]] = [array[j], array[i]]
  }
  return array
}

// 随机分组函数，确保全局唯一性
const generateSortedRandomGroups = (existingGroupsSet) => {
  const numbers = Array.from({ length: 49 }, (_, i) => i + 1)
  let groups = []
  let attempts = 0

  while (groups.length === 0 && attempts < 1000) {
    // 打乱数字顺序
    const shuffled = shuffleArray([...numbers])

    // 分为三组：两组 16 个，一组 17 个
    const tempGroups = [
      shuffled.slice(0, 16).sort((a, b) => a - b),
      shuffled.slice(16, 32).sort((a, b) => a - b),
      shuffled.slice(32, 49).sort((a, b) => a - b)
    ]

    // 转换为字符串检查唯一性
    const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
    const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

    if (isUnique) {
      tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr)) // 记录到全局唯一性集合
      groups = tempGroups
    }

    attempts++
  }

  if (groups.length === 0) {
    throw new Error('Failed to generate unique groups within 1000 attempts.')
  }

  return groups
}

const SIXTEEN_WAVE_COLOR_GROUPS = [
  [1, 2, 7, 8, 12, 13, 18, 19, 23, 24, 29, 30, 34, 35, 40, 45, 46], // 红波 17
  [5, 6, 11, 16, 17, 21, 22, 27, 28, 32, 33, 38, 39, 43, 44, 49], // 绿波 16
  [3, 4, 9, 10, 14, 15, 20, 25, 26, 31, 36, 37, 41, 42, 47, 48], // 蓝波 15
]

export const SIXTEEN_GROUP_MAP = {
  SIXTEEN_ASCENDING_GROUPS,
  SIXTEEN_PRIME_GROUPS,
  SIXTEEN_FIBONACCI_GROUPS,
  SIXTEEN_CENTER_EXPANSION_GROUPS,
  SIXTEEN_LARGE_MID_SMALL_GROUPS,
  SIXTEEN_PYRAMID_GROUPS,
  SIXTEEN_QUADRANT_GROUPS,
  SIXTEEN_JUMP_TWO_GROUPS,
  SIXTEEN_MODULO_FOUR_GROUPS,
  SIXTEEN_MIRROR_GROUPS,
  SIXTEEN_CROSSING_GROUPS,
  SIXTEEN_SUM_DIFFERENCE_GROUPS,
  SIXTEEN_DIAGONAL_GROUPS,
  SIXTEEN_LAST_DIGIT_GROUPS,
  SIXTEEN_MODULO_THREE_GROUPS,
  SIXTEEN_MULTIPLE_GROUPS,
  SIXTEEN_WAVE_COLOR_GROUPS,
}
